package com.sskj.mine.asset;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.util.PopUtil;
import com.sskj.mine.asset.data.RechargeBean;
import com.sskj.mine.asset.data.RechargeTypeBean;
import com.sskj.mine.asset.data.TradeAccountBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.asset.RechargeActivity;

import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.disposables.Disposable;


/**
 * @author Hey
 * Create at  2019/05/03
 */
class RechargePresenter extends BasePresenter<RechargeActivity> {


    /**
     * 币充值页面
     *
     * @param coin_type 币种类型（可充值列表接口返回的类型）
     * @return
     */
    public void recharge(String coin_type) {
        httpService.recharge(coin_type).execute(new JsonCallBack<HttpData<RechargeBean>>() {
            @Override
            public void onSuccess(Response<HttpData<RechargeBean>> response) {
                HttpData<RechargeBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.updateUI(httpData.getData());
                }
            }
        });
    }


    public void getType() {
        httpService.withdrawList()
                .execute(new JsonCallBack<HttpData<TradeAccountBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<TradeAccountBean>> response) {
                        HttpData<TradeAccountBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            Disposable dataDispo = Flowable.fromIterable(httpData.getData().getRes().getAsset())
                                    .filter(item -> item.getIs_act().equals("1"))
                                    .toList()
                                    .subscribe((rechargeTypeBeans, throwable) -> {

                                        mView.updateType(rechargeTypeBeans);
                                    });
                        }
                    }
                });

    }
}
